<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            width: 500px;
            border-collapse: collapse;
            text-align: center;
        }
        table,th,td{
            border: 1px solid #ddd;
        }
        th{
            background-color: blue;
            color: white;
        }
    </style>
</head>
<body>
    <table>
            <tr>
                <th class="allCheck">
                <input type="checkbox" name="" class="checkAll"> <span class="all">全选</span>
                </th>
                <th>商品</th>
                <th>商家</th>
                <th>价格</th>
            </tr>
            <tr>
                <td>
                <input type="checkbox" name="check" class="ck">
                </td>
                <td>小米手机</td>
                <td>小米</td>
                <td>￥1999</td>
            </tr>
            <tr>
                <td>
                <input type="checkbox" name="check" class="ck">
                </td>
                <td>小米净水器</td>
                <td>小米</td>
                <td>￥4999</td>
            </tr>
             <tr>
                <td>
                <input type="checkbox" name="check"  class="ck">
                </td>
                <td>小米电视</td>
                <td>小米</td>
                <td>￥5999</td>
            </tr>
    </table>
    <<script>
        const All = document.querySelector('.checkAll')
        const ck = document.querySelectorAll('.ck')
        All.addEventListener('click',function(){
            console.log(All.checked);
            for(let i = 0;i<ck.length;i++){
                ck[i].checked = All.checked
            }
        })
        for(let i = 0;i < ck.length;i++){
            ck[i].addEventListener('click',function(){
                // console.log();
                const cks = document.querySelectorAll('.ck:checked')
                All.checked = cks.length === ck.length
                
            })
        }
    </script>
</body>
</html>